/**
 * @author: p_haojiawu@tencent.com
 * @date: 2023-01-06 11:02
 **/
package com.tencent.qf.common.gateway.scrm;

import com.tencent.qf.common.util.SHA1Util;
import lombok.extern.slf4j.Slf4j;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;


@Slf4j
public class SCRMApiUtils {
    public static String sign(String appId, String appsecret, long time) {
        String rawString = "appkey=" + appId + "&time=" + time;
        String rawSign = SHA1Util.getHmacSHA1(rawString, appsecret);
        try {
            String sign = URLEncoder.encode(rawSign, "UTF-8")
                    .replaceAll("\\+", "%20")
                    .replaceAll("\\!", "%21")
                    .replaceAll("\\'", "%27")
                    .replaceAll("\\(", "%28")
                    .replaceAll("\\)", "%29")
                    .replaceAll("\\~", "%7E");
            return sign;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            log.error("urlEncode编码失败： " + e.getMessage());
            return "";
        }

    }
}
